﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Text;
using System.Web;
using Module.DataAccess;
using Module.EntitiesInfo;

namespace Module.BusinessLogic
{
  public class MemberBL
    {
      public static int Insert(MemberInfo memberInfo)
        {
            try
            {
                return new MemberDB().Insert(memberInfo);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        public static void Update(MemberInfo memberInfo)
        {
            try
            {
                new MemberDB().Update(memberInfo);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static void Delete(int idMember)
        {
            try
            {
                new MemberDB().Delete(idMember);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static MemberInfo GetInfo(int type, string param_1, string param_2)
        {
            try
            {
                return ObjectHelper.FillObject<MemberInfo>(new MemberDB().Select(type, param_1, param_2));
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static List<MemberInfo> Select(int type, string param_1, string param_2)
        {
            try
            {
                return ObjectHelper.FillCollection<MemberInfo>(new MemberDB().Select(type, param_1, param_2));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<MemberInfo> Select(int type, string param_1)
        {
            try
            {
                return ObjectHelper.FillCollection<MemberInfo>(new MemberDB().Select(type, param_1));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static List<MemberInfo> Select(int type)
        {
            try
            {
                return ObjectHelper.FillCollection<MemberInfo>(new MemberDB().Select(type));
            }
            catch (Exception ex)
            {
                throw;
            }
        }


        public static DataTable SelectTbl(int? type, string para_1, string para_2)
        {
            try
            {
                return new MemberDB().SelectTbl(type, para_1, para_2);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static DataTable SelectTbl(int? type, string para_1)
        {
            try
            {
                return new MemberDB().SelectTbl(type, para_1);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static DataTable SelectTbl(int? type)
        {
            try
            {
                return new MemberDB().SelectTbl(type);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static int GetCount(string keysearch,int active, DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow)
        {
            try
            {
                return new MemberDB().GetCount(keysearch,active,starDatetime, endDatetime, beginRow, endRow);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable Search(string keysearch,int active,DateTime starDatetime, DateTime endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new MemberDB().Search(keysearch,active,starDatetime, endDatetime, beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
          public static bool CheckAcount(int type, string param1, string param2)
          {
            try
            {
                return new MemberDB().CheckAcount(type, param1,param2);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

      public  static string GetActive(int active)
      {
          string status = "";
          if(active==1)
          {
              status = "Đã kích hoạt";
          }
          else
          {
              status = "Chưa kích hoạt";
          }
          return status;

      }

      public static string GetType1(bool typy1)
      {
          string status = "";
          if (typy1 == true)
          {
              status = "Yes";
          }
          else
          {
              status = "No";
          }
          return status;

      }

      public static string GetType2(bool typy2)
      {
          string status = "";
          if(typy2==true)
          {
              status = "Yes";
          }
          else
          {
              status = "No";
          }
          return status;

      }

      public static string GetType3(bool typy3)
      {
          string status = "";
          if (typy3 == true)
          {
              status = "Yes";
          }
          else
          {
              status = "No";
          }
          return status;

      }
      //update khi quên mật khẩu
      public static void MemberUpdatePassword(string email, string password)
      {
          try
          {
              new MemberDB().MemberUpdatePassword(email, password);
          }
          catch (Exception)
          {

              throw;
          }
      }

      public static void SaveCookie(string userName)
      {
          HttpCookie Cookie_Account;
          if (HttpContext.Current.Request.Cookies["CookieUser"] != null)
              HttpContext.Current.Response.Cookies["CookieUser"].Expires = DateTime.Now.AddDays(-1);

          Cookie_Account = new HttpCookie("CookieUser");
          Cookie_Account.Expires = DateTime.Now.AddHours(1);

          //EnCode AccountCode và Accountpassword trường khi lưu xuống Cookie
          Cookie_Account.Values.Add("userName", userName);
          HttpContext.Current.Response.Cookies.Remove("CookieUser");
          HttpContext.Current.Response.Cookies.Add(Cookie_Account);
      }
      public static string GetValue()
      {
          string valueCookie = string.Empty;
          string userName = string.Empty;
          if (HttpContext.Current.Request.Cookies["CookieUser"] != null)
          {
              valueCookie = HttpContext.Current.Request.Cookies["CookieUser"].Value;
              if (valueCookie != null && valueCookie != "")
              {
                  userName = valueCookie.Replace("userName=", "");
              }
          }
          return userName;
      }

      public static void DeleteCookie()
      {
          //Nếu Cookie tồn tại thì xóa cookie đó đi
          if (HttpContext.Current.Response.Cookies["CookieUser"] != null)
              HttpContext.Current.Response.Cookies["CookieUser"].Expires = DateTime.Now.AddDays(-1);
      }
    }
}
